const { Sequelize } = require('sequelize');

// 创建数据库连接
const sequelize = new Sequelize(
    process.env.DB_NAME,
    process.env.DB_USER,
    process.env.DB_PASSWORD,
    {
        host: process.env.DB_HOST,
        dialect: 'mysql'
    }
);

// 测试连接
const connectDB = async () => {
    try {
        await sequelize.authenticate();
        console.log('MySQL连接成功');
    } catch (error) {
        console.error('无法连接到数据库:', error);
        process.exit(1);
    }
};

module.exports = { sequelize, connectDB };
